package org.esti.controller;

import org.esti.model.UserRoles;
import org.esti.utils.VelocitySecUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.userdetails.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.management.relation.Role;

/**
 * @author ALoginov <a href="mailto:Artem.Loginov@exigenservices.com">Artem Loginov</a>
 * @since 10/14/11
 */

/**
 * return static part of application for example about page and home page
 */
@Controller
public class StaticController {

    @RequestMapping("/")
    public String showAdminHomePage() {
        if ( VelocitySecUser.allGranted(new String[]{UserRoles.ROLE_ADMIN.toString()}) ){
            return "redirect:/users";
        } else if(VelocitySecUser.allGranted(new String[]{UserRoles.ROLE_USER.toString()})){
            return "redirect:/"+VelocitySecUser.getPrincipal()+"/interviews";
        } else {
            return "about";
        }
    }

    @RequestMapping("/about")
    public String showAboutPage() {
        return "about";
    }
}